package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.*;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.wemedia.service.WmNewsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 陈辉
 * @data 2024 10:28
 */
@Slf4j
@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {

    @Autowired
    private WmNewsService wmNewsService;

    /**
     * 文章人工审核---文章列表查询
     *
     * @param weNewsPageQueryDto
     * @return
     */
    @PostMapping("/list_vo")
    public ResponseResult listVONews(@RequestBody WeNewsPageQueryDto weNewsPageQueryDto) {
        log.info("文章列表查询接收参数为{}", weNewsPageQueryDto);
        return wmNewsService.list_vo(weNewsPageQueryDto);
    }

    /**
     * 查询文章详情
     */
    @GetMapping("/one_vo/{id}")
    public ResponseResult newsDetail(@PathVariable Long id) {
        log.info("查询id为的文章详情{}", id);
        return wmNewsService.getNewsDetail(id);
    }

    /**
     * 人工审核失败
     *
     * @param wmAuthDto
     * @return
     */
    @PostMapping("/auth_fail")
    public ResponseResult authFail(@RequestBody WmAuthDto wmAuthDto) {
        log.info("人工审核id为{}的文章，审核未通过，因为{}", wmAuthDto.getId(), wmAuthDto.getMsg());
        return wmNewsService.authFail(wmAuthDto);
    }

    /**
     * 人工审核成功
     *
     * @return
     */
    @PostMapping("/auth_pass")
    public ResponseResult authPass(@RequestBody WmAuthDto wmAuthDto) {
        log.info("人工修改文章id为{}的状态{}",wmAuthDto.getId(),wmAuthDto.getStatus()==4?"人工审核通过":"审核失败");
        return wmNewsService.authPass(wmAuthDto);
    }

    /**
     * 内容列表
     *
     * @param reqDto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult list(@RequestBody WmNewsPageReqDto reqDto) {
        log.info("查询文章内容列表:{}", reqDto);
        return wmNewsService.pageQuery(reqDto);
    }

    /**
     * 发布文章
     *
     * @param wmNewsDto
     * @return
     */
    @PostMapping("submit")
    public ResponseResult submit(@RequestBody WmNewsDto wmNewsDto) {
        log.info("发布文章：{}", wmNewsDto);
        return wmNewsService.submit(wmNewsDto);
    }


    /**
     * 自媒体文章上下架
     *
     * @param wmNewsDto
     * @return
     */
    @PostMapping("down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsDto wmNewsDto) {
        log.info("本次自媒体文章上下架操作：{}", wmNewsDto.getEnable() == 1 ? "上架" : "下架");
        return wmNewsService.downOrUp(wmNewsDto);
    }
}
